﻿using System.Collections.Generic;
using System.Linq;
using Melee.DataContract.Views;
using Melee.Models.Entity;
using Melee.Infrastructure.Configuration;

namespace Melee.DataContract.Extension
{
    public static class AreaExtensionMethod
    {
        //public static AreaView[][] ConvertToAreaViewOfMap(this IEnumerable<Area> areas)
        //{
        //    AreaView[][] areaViews = areas.GroupBy(a => a.Y).Select(ga => ga.Select(a =>
        //    {
        //        AreaView area = new AreaView
        //        {
        //            Img = string.Format("images/area/{0}", a.Img),
        //            X = a.X * ApplicationSettingsFactory.ApplicationSettings.AreaLength,
        //            Y = a.Y * ApplicationSettingsFactory.ApplicationSettings.AreaLength
        //        };
        //        area.Points = a.Points.GroupBy(p => p.Y).Select(gp =>
        //            gp.Select(p => p.ConvertToPointView()).ToArray()).ToArray();
        //        return area;
        //    }).ToArray()).ToArray();
        //    return areaViews;
        //}

        public static IEnumerable<AreaView> ConvertToAreaView(this IEnumerable<Area> areas)
        {
            return areas.Select(a => new AreaView
            {
                Img = string.Format("images\\area\\{0}", a.Img),
                X = a.X * ApplicationSettingsFactory.ApplicationSettings.AreaLength,
                Y = a.Y * ApplicationSettingsFactory.ApplicationSettings.AreaLength,
                Points = a.Points.ConvertToPointView()
            });
        }
    }
}
